<template>
  <el-row :gutter="40" class="panel-group">
    <el-col v-for="(item, i) in options" :lg="6" :sm="12" :xs="12" class="card-panel-col">
      <div class="card-panel" @click="handleSetLineChartData(item.type)">
        <div class="card-panel-icon-wrapper" :style="'color: '+ item.color +';'">
          <svg-icon class-name="card-panel-icon" :icon-class="item.svgName" />
        </div>
        <div class="card-panel-description">
          <div class="card-panel-text">
            {{ item.text }}
          </div>
          <count-to :duration="item.duration" :end-val="item.endValue" :start-val="item.startValue" :decimals="item.decimals" class="card-panel-num" />
        </div>
      </div>
    </el-col>
  </el-row>
</template>

<script>
import CountTo from 'vue-count-to'

export default {
  components: {
    CountTo
  },
  props: {
    options: {
      type: Array,
      require: false,
      default: function () {
        return [
          {
            text: '访客',
            startValue: 0,
            endValue: 102400,
            duration: 1000,
            svgName: 'peoples',
            color: '#40c9c6',
            type: 'newVisitis',
            decimals: '0',
          },
          {
            text: '消息',
            startValue: 0,
            endValue: 10240,
            duration: 1000,
            svgName: 'message',
            color: '#36a3f7',
            type: 'messages',
            decimals: '0',
          },
          {
            text: '金额',
            startValue: 0,
            endValue: 452400,
            duration: 1000,
            svgName: 'money',
            color: '#f4516c',
            type: 'purchases',
            decimals: '0',
          },
          {
            text: '订单',
            startValue: 0,
            endValue: 5690,
            duration: 1000,
            svgName: 'shopping',
            color: '#34bfa3',
            type: 'shoppings',
            decimals: '0',
          }
        ]
      }
    }
  },
  methods: {
    handleSetLineChartData(type) {
      this.$emit('handleSetLineChartData', type)
    }
  }
}
</script>

<style lang="scss" scoped>
.panel-group {
  margin-top: 18px;

  .card-panel-col {
    margin-bottom: 32px;
  }

  .card-panel {
    height: 108px;
    cursor: pointer;
    font-size: 12px;
    position: relative;
    overflow: hidden;
    color: #666;
    background: #fff;
    box-shadow: 4px 4px 40px rgba(0, 0, 0, .05);
    border-color: rgba(0, 0, 0, .05);

    .card-panel-icon-wrapper {
      float: left;
      margin: 14px 0 0 14px;
      padding: 16px;
      transition: all 0.38s ease-out;
      border-radius: 6px;
    }

    .card-panel-icon {
      float: left;
      font-size: 48px;
    }

    .card-panel-description {
      float: right;
      font-weight: bold;
      margin: 26px;
      margin-left: 0px;

      .card-panel-text {
        line-height: 18px;
        color: rgba(0, 0, 0, 0.45);
        font-size: 16px;
        margin-bottom: 12px;
      }

      .card-panel-num {
        font-size: 20px;
      }
    }
  }
}

@media (max-width:550px) {
  .card-panel-description {
    display: none;
  }

  .card-panel-icon-wrapper {
    float: none !important;
    width: 100%;
    height: 100%;
    margin: 0 !important;

    .svg-icon {
      display: block;
      margin: 14px auto !important;
      float: none !important;
    }
  }
}
</style>
